<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>
	<body>
		<script>
			var names = ['abc', 'cba', 'nba']

			/* names.forEach(function (item) {
				console.log(item)
			}) */

			// 版本一
			/* function hyForEach(fn) {
				for (var i = 0; i < names.length; i++) {
					fn(names[i], i, name)
				}
			}

			hyForEach(function (item, index, arr) {
				console.log('------', item, index, arr)
			}) */

			// 版本二
			/* function hyForEach(fn, arr) {
				for (var i = 0; i < arr.length; i++) {
					fn(arr[i], i, arr)
				}
			}

			hyForEach(function (item, index, arr) {
				console.log('------', item, index, arr)
			}, names) */

			// 版本三
			/* names.hyForEach = function (fn) {
				for (var i = 0; i < this.length; i++) {
					fn(this[i], i, this)
				}
			}

			names.hyForEach(function (item) {
				console.log(item)
			}) */

			Array.prototype.hyForEach = function (fn) {
				for (var i = 0; i < this.length; i++) {
					fn(this[i], i, this)
				}
			}

			names.hyForEach(function (item, index, arr) {
				console.log(item, index, arr)
			})
		</script>
	</body>
</html>
